"use strict";
const fs = require("fs");
const path = require("path");
const ctrl = {};
const readData = (path) =>{
    return new Promise(function(resolve,reject){
        fs.readFile(path,function(err,data){
            if(err){
                reject(err);//文件存在返回true
            }else{
                resolve(data);//文件不存在，这里会抛出异常
            }
        });
    });
}
ctrl.ca = async (ctx) => {
    const home = path.join(process.env.HOME || process.env.USERPROFILE, '/.anyproxy/certificates', 'rootCA.crt');
    ctx.set('Content-disposition','attachment; filename=rootCA.crt');
    ctx.set('Content-type', 'application/x-x509-ca-cert');
    ctx.status = 200;
    ctx.body=await readData(home);
};
module.exports = (_, pre = '/proxy/') =>{
    _.get(pre+ 'ca', ctrl.ca);
};